// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   address_change_ok.java

package stock.config.stock;

import include.nseer_cookie.counter;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class address_change_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;

	public address_change_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		counter count = new counter(dbApplication);
		nseer_db_backup1 stock_db = new nseer_db_backup1(dbApplication);
		try
		{
			if (stock_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String stock_ID = request.getParameter("stock_ID");
				String stock_name = request.getParameter("stock_name");
				String responsible_person_ID = request.getParameter("responsible_person_ID");
				if (responsible_person_ID.equals(""))
					responsible_person_ID = "09020000000000100000";
				String responsible_person = "";
				int n = 0;
				int m = 0;
				String sql2;
				for (StringTokenizer tokenTO6 = new StringTokenizer(responsible_person_ID, ", "); tokenTO6.hasMoreTokens();)
				{
					sql2 = (new StringBuilder("insert into hr_config_human_id_temp(human_ID) values('")).append(tokenTO6.nextToken()).append("') ").toString();
					stock_db.executeUpdate(sql2);
					m++;
				}

				sql2 = "select distinct human_ID from hr_config_human_id_temp";
				ResultSet rs2 = stock_db.executeQuery(sql2);
				rs2.last();
				if (rs2.getRow() != m)
					n++;
				sql2 = "delete from hr_config_human_id_temp";
				stock_db.executeUpdate(sql2);
				for (StringTokenizer tokenTO = new StringTokenizer(responsible_person_ID, ", "); tokenTO.hasMoreTokens();)
				{
					sql2 = (new StringBuilder("select * from security_users where human_ID='")).append(tokenTO.nextToken()).append("'").toString();
					rs2 = stock_db.executeQuery(sql2);
					if (rs2.next())
						responsible_person = (new StringBuilder(String.valueOf(responsible_person))).append(rs2.getString("human_name")).append(", ").toString();
					else
						n++;
				}

				if (n != 0)
				{
					response.sendRedirect("stock/config/stock/address_change_ok_a.jsp");
				} else
				{
					String sqll = (new StringBuilder("select * from stock_config_public_char where stock_ID!='")).append(stock_ID).append("' and stock_name='").append(stock_name).append("'").toString();
					ResultSet rs = stock_db.executeQuery(sqll);
					if (rs.next())
					{
						response.sendRedirect("stock/config/stock/address_change_ok_b.jsp");
					} else
					{
						String sql = (new StringBuilder("update stock_config_public_char set stock_name='")).append(stock_name).append("',responsible_person_ID='").append(responsible_person_ID).append("',responsible_person='").append(responsible_person).append("' where stock_ID='").append(stock_ID).append("'").toString();
						stock_db.executeUpdate(sql);
						response.sendRedirect("stock/config/stock/address_change_ok_c.jsp");
					}
				}
				stock_db.commit();
				stock_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
